refactoring: get rid of nested for loops