major cleanup and refactor. Finally with tests!
generalise the handler
bind the handlers to the correct object...
fix unit test for new api and add example code