Improvement to handling of set_settings and set_permission.
Improvements to last change.
Merge pull request #87 from roydude/v1-train

V1 train