handling loops better