This will increase efficiency ~100x. Possibly merge function with contvar_peh if it makes sense to do so