Refactored and made scrolling work properly