Writing middleware

TODO