adding unit testing and pulling apart code so its testable