There was a lot of effort put in to changing how those machines work, based largely on the work of a few independant researchers in the early 2000’s. Newer machines are more secure, auditable, and have a documented paper trail of all votes that can be recounted. These companies had to be shamed into doing the right thing, but at least they did it.
Many machines now are paper based, the machines just scan the paper and deposit it in a lockbox, and the physical paper can be recounted if necessary. These are the machines I use in my district.
The ballot is scanned right in front of you, and if you made a stray mark that would cause the ballot to be invalidated, or it detects an over/under vote, it informs you so that you have a chance to destroy the ballot and re-vote if necessary.