Small fixes.

Please refer to the commit messages for details.