code for fitting added