fix iterating through empty result set