A real world example of refactoring JS to make it unit testable