Added decoding feature (not quite working yet), moved some functions around