Minor refactoring for PR#581