Fix bug mentioned in issue #162 and another small bug.
Merge branch 'master' into v1.0