Fix module list regeneration fixes #1014

fix module regeneration and saving of module states based on core compatibility. Clean up and reorganize some code in the Api file. fixes #1014

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #1014
| Refs tickets  | -
| License       | MIT
| Doc PR        | -