fixed back button bug, DRYd out JS