Clean up code according to review, add a check for invalid password.