Catch exceptions from bad short packets

Also refactored a few parameters into global variables rather than
passing them around through several function calls.