Make login a little more robust

Adds some extra handling so that issues logging in provide a useful error message. Also a few comments