refactored using macros