minor bugfixes and cleanup