Finally got to the bottom of memory error.