refactor js & dialog