better middleware recipe