Restructure code to allow reading packets from a file