write test, small fixes and refactoring, #36