Refactored UDP handler.