adding memoryerror exception handling