merge similar code