Moved auth code to separate file