bug fix and add comments