Various major bug fixes and improvements.