Moved common functionality into macros for ease of maintenance.