Refactor string checking. No functionality change.