fix module regeneration and saving of module states based on core compatibility. Clean up and reorganize some code in the Api file.
correct syntax error in template
Merge pull request #2091 from craigh/ModRegen

Fix module list regeneration fixes #1014