adjusting logic for null dates