refactor & demo

completely refactored the code to work correctly with history
created a demo to illustrate use