fixing last packet detection