Updated the equals method to work well with inheritance