improved equals method for subclasses