Fix application's shutdown sequence