refactor for testing purpose