refactor comments reply javascript code