csh loop refactor