Not my best code ever \U0001f648, but given the current else-if structure there isn't a much better solution, except refactoring it into a small helper. I tried following the current code structure (raw if statements), I can refactor this if it's found to be too hairy.