Todo added: better shutdown procedure