Fixed bug in usedNames query