Refactored common code into method.