Added error checking - previously a wrong password did not lead to an error.