Cleaning, debug and various minor improvments