Moved authentication to new function