Changed null logic slightly