DRY up backToTop function and fix persistence bug