Changed code to take into account daemon process