re-factoring to make things more testable