fixed absolute value problem in algorithm