bugfixes and cleanups