Big commit with all fixes.

Fixed things came up in comments.