Query tested against some examples from the Alfresco wiki, OK now, few bugs squeezed out.