Bugfix and improvements