cleaned and finished linear time