Fixed the NULL handling bug finally