fixed thread so it starts and stops properly