Fixed some exceptions on shutdown