add comments and fix bugd