Make some chanes based on feedback. Moved the authentication logic to its own file.