Using passport for authetication, some refactoring, and minor fixes