remove sub, add more isnil checks