Fix warnings/crashes on quit