remove duplicate code in server.py