Minor fixes and clean ups.

Minor fixes to prevent crashes and some clean ups.