fix bug and add comments