Implemented  middleware, and made convertToHTML into that