Generate better badarg error in operators

Also took chance to do some small cleanups.