Add module references support for the module code generator - transfered over from the old Nii unicorn branch