UDP bind() error handling and other refactorings