Generate better badarg error in operators

Also took chance to do some small cleanups.
Improve string.format to handle more options