Added some optimzations for high memory usage cases.