Fix NPE on shutdown