Adopted the changes from PR #464 with nested collections to master branch