Included changes suggested by @jonbinney