added middleware pattern