Refactor to support stream decoding