reduce the duplicated code