separated main/daemon functions into main.c