made script more smarter to record pid