Add unit tests and refactor snippetsUnits.device_units, which is widely used and obscurely implemented.