added handlePacket() for parsing packets