Fixed unitsToObject function to accept strings