cleanup and bugfixes