Improved equals check