refactor to remove nested for loops, change test name for readability