improve and simplify looping structures