Use macros and higher-order functions to reduce code repetition