Separate the branches into two smaller functions. This code is difficult to read.