applying patch from DS-1410, merging with changes from DS-1503 / PR #196

The submitted patch for DS-1410 had a few conflicts with PR #196, this pull request resolves those conflicts.