rewrote program with threads