[DS-1085] Apply patch (slightly updated) from Jira ticket

Rebased #164 on top of current master.