Fixed some bugs, put dialog.js after ui.js