clean up private algorithm code

The private algorithm has now been split up into more readable functions
like the non-private algorithm.