fixed all memory bugs