Beginnings of Clean Up

It's only 450 lines long but I want to organise this better
so that it is easy for me to expand and fiddle with in the
long term.