discovered a monotonicity bug, haven't located the error yet
fixed infinte loop and monotonictiy bugs