Some functions and algos implementation