Can you factor out this logic into a helper function so we do not repeat it for fan 1, 2, and 3?