some cleanup and bugfixing