Updated processing script to be more robust in encoding output