ticket #3 middleware. Some functional and unit tests. With basic implementation