Make __eq__ code more DRY