Simplified event handling code + got popstate working.

Seems to work, not sure about detaching..