added comments and formatted the code