better seperation to functions
some more small plumbing in inner functions