massive yet very slight refactoring