replaces some messy code with cleaner macros