This seems to be a very robust solution. The only drawback is that there must not be any overlap between variable and unit names (like m for mass and m for meter). Yet, this is easy to handle, as you either aren't going to expose the unit names in the feedback or you can use texput to substitute whatever you want for output.
I'll open an issue on github for further discussion.