added signal handler and improved validation