encode strings so it does not fail when writing