Use PACKET logging level to log errors in packet commands.
Fix possible loop logic error.
Do not allocate packet unless necessary.