Major refactor of thread posting code