Added encoding option (defaults to UTF8) to input and output values