Added support for multiple instances of a given module.

- Introduded the concept of generic/specific ids.
- Added wrappers for counting all modules, modules with a given type and
  modules witha  given generic id.
- Updated sample code.
- Several other small changes here and there.