Add tests, fix bugs. Updates #65.