Fixing problem at shutdown