refactor: check for null and undefined