Some major bug fixes