cleanup and bugfix