Add middleware system
First tests passing