Fix #86 - Select distinct item ids

I worked out how to create a clean tree, so here is a pull request to fix #86