Dealing with undefined in JS is a pain