Reduce some code duplication using a macro