Fix broken popstate logic