Updated login / logout logic