More memory efficient + error fix