fixing read packet function