Change string function to sprintf and remove temp var