Modified recursive functions into 'for' loops.