Corrected codegen to support shadowed module names.

Fixes #601.