introduce messages types & refactor middlewares sample