refactoring to reduce code duplication and to conform with coding standard