Fix some bugs and add some commentaries