Implemented daemon function.

Added signal handler