Refacoring of large parts of the code. Enhancements #3
Better handling of some errors from bart. Enhancment #1