correct some bugs and rewrite the code
Merge pull request #50 from JinYu-Syue/master

correct some bugs and rewrite the code