improved the code for detecting login failures
fixed textual errors in comment