changed threads and added game finished detection