middleware now functional and tested