fix some bugs and optm