Moved popstate guard to popstate event