Bugfixes and improvements