refactor and fix scrolling