I think this is towards a final version. Using a let at the beginning simplifies a lot of things. Only one if is needed to handle an empty filter-groups list as well as appending to an existing list