rework to deduplicate code again