Fix equals implementation

Fixes #1016