move start_daemon code to main script