More tests and bugfixes found through tests