refactor server.py