fixed bugs with reference to @pid variable