Feature/middleware api

Adds middleware support via callback hooks