fixing bugs with memory