Added comments and formatted the source code.