Simplify checking for undefined, fix typos along the way