Replaced char operation by string operation, make the program more robust