Fixed db_middleware