Added 'Out of Memory Error' handling code to decrease the crash risk