memory management bug fix