Cleaning, fix bug reduction, check for nans