Miscellaneous bugfixes and amendments.

Change-Id: I8a43465340e30ec256498372c36bc59180c16563
Merge "Miscellaneous bugfixes and amendments."