Updating the scrolling logic to make scrolling smoother