Wouldn't it be a bit cleaner to extract a method for initialization of 'code' (lines 90,91,95-98)?
Additionally, mixed within these is initialization of all_vars and loop_vars, I guess that could be moved up/down for better readability?