finally some whole algorithms