memory leak fixes from Matt Tyson