So I have this function but I need to make it smaller as there are a lot of nested loops and branches, how can I use helper functions to solve my problem without changing th