consolidate duplicate code