added comments and documentation.