memory leak fixes / other fixes