Fix more bugs, fix some tests.

Some other tests still failing...

Change-Id: I3c65a43822840e7e64c3c3cfe759e1de51272581