added initial middleware implementation