fixed authorize function