Restructure code from r224097. NFC