improved app:middleware