Changed the nextExpectedPacketNumber variable to store the correct value instead of the value shifted by 1.