partial algorithm
almost