code cleanups, minor bugfixes