reworked packet handler and optimized