Added comment and improved efficiency

Refine the data frame and remove redundant code