fix handling for follow-up msgs and tidied up the code