Added signal handling for proper cleanup