ref #4021 - minor changes and refactoring