add comments and refine some codes