Fix some bugs, release 1.3.1.
Merge branches 'dev-1.3.1' and 'master'