algorythm implemented, working