Ensure nested modules are properly defined, closes #1057