add better null and undefined handling for model