First version of algorithms for PhD thesis