Applied bugfixes from upstream repository.