Sketch out initial middleware implementation

Still fails, though. Need to think through this.