1)Corrected an error checking .. If spid is null then instead set pid as
0