Fix for visited-node logic