remove some duplicated code