Add support for multiple PIDs and improve signal handling