Dialyzer fixes.

Some of these are unused functions, or cases that can never match.
Others are code errors which have now been fixed.