fix #1731 and #1733. Remove all workarounds for the agj non structured output, and fixes some minor bugs