Fix error handling and adding packet dispatcher logic