Code improvements and fixes, and added PacketHandler