replace one-liner with a custom module.

@adrienthebo suggested this may be generally useful, so we replace the
unreadable one-liner with a utils module. We also spread the if over
multiple lines to make it look more like the rest of the source-code and
generally more readable.