consolidate similar code