pulling packet reading code into a separate function