Fix some AST bugs

`transform` and `rta` have some issues that lead to inconsistant information on the AST.
This series fixes them.

Note: Most commits extracted (cherry-picked) from #386 and #367