Better handling of authentication, fix #137.