make a function out of the double for and if that creates a list, and use it also elsewhere (in the PR there is also something like this).