Better string handling to be cross compatible with python 2 and 3