refactor for testing