refactor for unit testing