misc & memory leak fixes