Memory leak fixes, compilation fixes