use macro to deduplicate code