Fixed some bugs. Replace alert with dialogs.