Fix null reference exceptions found via Crittercism