attempting a more robust encoding handling