fixed not using abs() for negatives during loops