Fixed bugs with polling and terminating processes