Start of refactored Z39.50 code