These seem to be entirely independent, so moving the body of the if statements to separate functions should be fine.