updated code to be a bit more testable