minor bugfixes and code cleanup