optimize onpopstate event handler