Better logout and login redirect but still buggy