Do signout and environment stuff

sign out pattern copied from backdrop but I don't fully understand why
this was necessary, needs discussion