Cleaned the shutdown sequence by packing it in its own function