Refactoring auxiliary function