Added out of memory error handling