splitting out more code to make it testable