Fixed bugs in authorization