merging duplicated code