Changed the formula to detect when to stop scrolling down.