Fix ExpandImport ordering

It should be called sooner, otherwise some analysis choke on an unknown
identifiers which turns out to be a name imported from a module.
Rework generator representation

Still not perfect, but at least does not lead to bugs in the validation.