Added a basic test suite, and fixed a few minor bugs.