Added some more tests. Fixes some minor bugs.