more refactoring for use with flask, error handling when username/password is no good