Improved scrolling logic