Use middleware pattern if available. Closes #2