Refactor some common code into utilities class.