Add save file dialog and clean some codes