more bug fixes and improvements