return middleware function instead of object