Some bug fixes.
Merge pull request #2997 from gyohk/master

Some bug fixes.