Fix looping over records