moving loop into rules