Properly handle namespaces in +o proxy code generation

Extracted from #28 and based on the latest master for easier review