Completion of test suite and bugfixes