cleanups and bugfix