Major refactor to structure of the application. Fixes #36