Refactor server.py (increase readability)