major bug fixes and improvements