Added SIGHUP, SIGINT and SIGTERM handler, split up message processing