fix some bugs and improvements