Added cleanup code, so that it would be possible to kill the program without having lots of zombie processes.