Merged in fixes from pullrequest.