cleaned up utility loop