More tests, bug fixes