Some algorithms implemtations