added check for y-value difference if exceeds threshold