Added metdata save and load capability.

- Metadata is loaded at the beginning of the run (if it exists) and
  saved at the end.
- All references to 'config' changes to 'state'