Merging duplicated code