Merge from google.

Lots of change - see the commit list for detail. 
Yeah - this solves all sorts of problems.