add out of memory check