cleanup and bugfixing