Updated logout logic