fixing a memory overflow