Removing unneeded code in middleware.py