Minor bugfixes and improvements