Fix a few bugs and rearrange some OS auth steps