Several smaller bugfixes and improvements.