Merge duplicate code