adding extra nil check that hopefully fixes an error I cant reproduce