Find some bugs and modify the codes