Still refactoring Dialog javascript