Added signal handler, fixed some minor issues