found some non function variables were written by each thread, moved into function definition