better middleware architecture