Fix proper shutdown