Merge "Fix shutdown sequence to avoid SIGSEGV when running am command"