Some minor bugfixes and improvements