A bunch of changes, as per legoktm's code review

Change-Id: If8533fc128d0e72010be2555dc1a72c0d78e6bca