fix out of memory bug