Made few changes in implementation - keeping track of pid