start splitting daemon main() into smaller functions, state related variables moved to separate structure