refactored thanks to specbdd