refact reply function