function [nothing] = RefineAlignments(this_moving_stack,optreg,calculated_params)

first_target_stack = calculated_params.corrected_first_target_stack;
last_target_stack = calculated_params.corrected_last_target_stack;

first_moving_stack = calculated_params.corrected_first_moving_stack;
last_moving_stack = calculated_params.corrected_last_moving_stack;

fix_total_number_stacks = optreg.fix_total_number_stacks;


if fix_total_number_stacks
    difference = (last_moving_stack - first_moving_stack) - (last_target_stack - first_target_stack);
    if difference > 0
        first_moving_stack = first_moving_stack + difference;
        fprintf('taking later first_moving_stack so that number of stacks in both groups will be the same');
    else
        first_target_stack = first_target_stack - difference;
    end
end

time_offset =optreg.time_offset;

moving_nuclei_seg =-1;
moving_nuclei_centers = -1;

if max(first_target_stack,this_moving_stack+time_offset) > last_target_stack
    correct_target_stack = last_target_stack;
else
    correct_target_stack = max(first_target_stack,this_moving_stack+time_offset);
end

if fix_total_number_stacks
    correct_target_stack = this_moving_stack - (last_moving_stack - last_target_stack);
    if correct_target_stack > last_target_stack
        correct_target_stack = last_target_stack;
    elseif correct_target_stack < first_target_stack
        correct_target_stack = first_moving_stack;
    end
end

correct_target_stack

RegisterByNucleiRefineCross(optreg,calculated_params,this_moving_stack,correct_target_stack,true,true,false,12341,true,true,moving_nuclei_seg,moving_nuclei_centers);

nothing = 'nothing';