finish update factor
fix bug in calulating distance