fixed faulty `merge` implementation. Added reference equality checks as @evancz suggested