Memory leak fixes and more RAII...more leaks could still be fixed though