Added decoding and changed structure of code