Move code a bit to avoid a few declarations. NFC.
Fix implicit conversion of NULL constant to 'bool'.