refactor to thread config through (not quite working yet)