Added authentication and major refactoring