refactorred many parts, including timer and thread creation