Added more comments and documentation.