move some more code to subs