Reworked macros as functions. This avoids the use of dynamic scope.
Added support for ontology as first argument.
Removed the various dynamic scope variables and their usages.