Python migration WIP.

Re-arrange code to better support migration.

[test]