Fix bug mentioned in issue #162 and another small bug.