streamlined algorithm
tidying