Refactor warcmiddleware.py