move middleware into handlers