added middleware delegate with tests