refactor of daemon