refactor to better support testing