Refactoring: move common code to Utils