Add validation and improve string concatenation

Also fix support for newer versions of Python.