optimize codes and add daemon proccess function