some refactoring for supporting server and login