several bug fixed and improvements