Multiple fixes to logout and replace