refactor daemon