Fixed exception with document query.
Added support for 3-stage macro compilation.