Reorganized packet handeling code out of main class.