major refactoring and clean up for UDP side