moved reusable functions from daemon.c to message.c