major refactoring/improvements to authentication & db