re-work app-specified callbacks into a 'middleware' system