fixes to improve robustness

I added some checks on critical conditions that may be reached when using few data, plus improvements for cmake and the external build of the Openblas library