extracting daemon functionality to separate script