Algorithm appears perfect