Fix bug and add some comments