corrected the linear algorithm.