Refactored parsing of macros

Fixes: #1052