pulled out the duplicated code part