fixed write file and trying to fix decoding faults