Canonicalize imports and finalize variables.