refactor code, make work with 12-bit data and 6-bit id