Enable testability

In order to enable testability, this is a small refactoring to extract responsibility to it's own object and created some rspec tests. Merge if you like :-)