Fix out of memory bug