Divided middleware into modules.
Added subscriptions for events.