Refactoring for a more flexible UTF8 decoding (streams ready)