Various patches and improvements