refactored common code into a tool class with static methods.