Fix handling of unit types. Hopefully the parsing hasnt become too ugly?