Fixes exception on shutdown