Improoved algorithm, now it ALWAYS find a solution