Further bugfixes and improvements