Added several checks for nulls