Various to try and strengthen the code against Marionette issue 859439.
Merge pull request #181 from roydude/v1-train

Various to try and strengthen the code against Marionette issue 859439.