implement reformatted version of Michal Marczyk's optimized case macro