Fixed #5 and added tests for it. Also fixed some other tests.