cleanup of code, bugfixes