refactor middleware actions

cleaner way of passing over middleware from changes in #16