More minor bugfixes and cleanup.