Fix various problems on the way to make authentication working.