Fixed bug in authentication check