refactor, + unit tests