move authentication to main code