Complete rewrite using Floyd's Algorithm