pkg/units: Refactored common code to single func

Both functions perform the same logic and they just vary on the base
units. We can refactor the common code into a single place.

Docker-DCO-1.1-Signed-off-by: Francisco Carriedo <fcarriedo@gmail.com> (github: fcarriedo)