Feature/iotcore 112 integration

Fix a problem with the dynamic middlewares (multiple applications of apply) and add some debug logs. Please, DO NOT remove the branch (it will be reused for the integration process).