More tests and some bugfixes