simplified loops, improved clarity