added comments and documentation