refactor deamon