Add some unit tests and fixes to make them pass

Run the tests in the root directory with nose.