middleware now supports pre and post actions