pkg/units: Refactor common code

Found some duplicated code that could be refactored into a common place.

The individual commits tell the story ;).

p.s. Sorry if I'm missing something on the contribution process, I'm trying to get a sense of it. Let me know if I should have done this differently.
@fcarriedo You could update these to use the constants as well.