refactored scrollToTop function