consolidate conversion code