big refactor to turn this thing into a friendly package.