minor refactoring
pull upstream