getting the loops right