cache vars where poss, move dev object creation into iffy to stop errors, remove global declaration