Pr 115 refactor changes

This contains some improvements to the code quality based on feedback from #115 

Mainly a bunch of things were extracted out into either functions or the responsibility was moved around a bit to put code in places where the responsibilities make a bit more sense.

Please review @costford @maartenvg 

Thanks for your initial work on the feature @voberoi :)