Fixing out of memory error