refactor, increase test coverage