Can we extract this as something like `function ensureSafeInteger` and get rid of the comments?