Fixed a bunch of places where nil checks were causing problems.