Refactored common function.