Added streaming decoding and some optimizations