Merge pull request #25 from emtwo/unit-tests

Add unit tests.
Fix bugs.