Fixed authorize function