Handle nested modules in signature generation

Close #678.