Refactored scrolling code