get rid of duplicated code