various bugfixes and style fixes