Fixed some bugs.

General code tidying up and making the framework more extensible for
future stuff