Encapsulate middleware