Bb 1895

Rebased on crazy-branch and fixed various issues causing import errors and tests failing.