refactory to integrate modifications on mosesacs/daemon