Added decoding functions, needs fixing though