minor refactor, debug, tests