adding tests, refactoring handlers.