fix bug when run as a daemon