Massive refactor

NB: Totally unacceptable due to licence removal ([due to intelliJ, not me](https://twitter.com/JackWeirdy/status/473195780095107072)), and was pushed only so I could test on other machines. This commit will be removed in due course with a QA'd one.