Started adding tests

This breaks a lot of stuff.
Finish adding tests. Move the app definition into a method, so it can be used in tests, and break out the handlers into their own modules.
Merge branch 'adding_tests'