Added Out of memory exception handling