Fix some bugs and modify codes