I cleaned up this section of the code using `getattrs`, which avoids the tedious `if-else` statements.