Deduplicated the if statements