Added some sanity checks for null variables