added comments and fixed formatting