added middleware support