quick fix - improve memory handling