added implementation of middleware