in process of tidying up alogrithms