Added additional comments and formatted the code

Added additional comments and formatted the code