Refactoring add util function to extract common processes