fix duplicated code