reorganize format of reply; reorganize some code