Added more tests, updated module to fix bugs found by tests.