fix encoding issue, still fails sometimes, might have bad performance