Added signal handler.
Code refine.