added handling for 'out of memory' scenarios.
added documentation.