some bug fixes and improvements.