Reduce duplicated code