Added authentication. Moved functions to their own files.