please move each block of the condition to its own function