bug fixes exposed by R check