Some fixes and improvements