Address various code review comments.

Thanks for the thorough review. I think I've got all your comments addressed here. Please take another look.