Made some more minor refactors to see if we can't simplify the logic here.