Implement recursive compare