Fixed errors with NullPointerExceptions.