Fixing reference to query values #661