edited preprocess and calcResid to include minIntensity