fixed major bugs in the auth code implementatopm