Changed the way authentication is done

Couple of issues with the previous mechanism