fixed a bug where threads[] was being overwritten