reorgranize middleware, conditional stack

- move middleware to separate file
- add conditionals before optional middleware
Add instance methods for start and stop