Cleaned up; fixed emergency shutdown