tidier implementation of sameContents