Fix remaining memory leaks, fix problem with 63cca8f