Avoid referencing undefined variables

Define all those vars, otherwise they can get referenced while undefined if the (pos > -1) check fails at line 184