refactor to enable unit testing