Tests for #306
refactor BME generation for #306
fix #306