bugs fixes and improvements