added optimized version with macros