added simple demo app, and cleaned up a bit of the middleware code