Reformat and comments

Reformated the code and added more comments