Simplified logic to avoid previously visited pages