Refactor some code into a controller module

Closes #23 

Addresses more of #19 and #15 and a first attempt at part of #18