Fix one to one query

This is the same as PR #194, except is is rebased with the master branch.