bug fixes and improvements