refactoring code and add reply