refactored popstate