Refactoring preparatory to code clean-up (no functional changes, all tests pass).
clear distinction between raw (C++) and cooked (Javascript class instances) types.
Major re-factoring for auto downcasting
Fixed a lint error