refactor middlewares out of __init__