Tests and fixes for #970