added handlepacketin function