clear ParameterCellCorrection

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

counter = 0;
for i = first_moving_stack:last_moving_stack
    counter = counter +1;
    ParameterCellCorrection{counter} = {i,optreg,calculated_params};
end

nothing = startmulticoremaster(@RefineAlignments, ParameterCellCorrection);