Some algorithms implementation