Extract duplicated code into macro