changed write_misfit to sum_residuals
fixed trace normalization bug