Refactor to namespaces.
Backport refactor from 2.0
Refactor to namespaces.
Backport changes from 2.0