v3.1 bug fixes to merged code