Added more threads and structure. Still needs comments.