Refactor: split into jobs to split into threads

Threads not working right now but the loop is
split up to prepare for it. Also writing to file.