fixed incorrect login handling. Still not perfect