Beef up unit name validity checking

Fix #793