Again, I think that adding comments to that function will help. Is rather complex and if we need to maintain it in the future, we need as help as possible for that task placed in the code.