Added in unit tests to test the Tornado-specific code and fixed a few bugs.