Ported small refactor.