dedup some code