Many fixes and improvements