consolidated code from an old repo, elided a couple of functions that are provided by strconv