added some algorithm comments