corrected nan problem