Reordered login function