Create shutdown function