refactor with test coverage