Fixing shutdown bugs