Fix bad module naming when using custom output, again …

This mostly reverts commit d0f4149
and fixes the issue described.