started reworking middleware implementation