Refactor code

- Clean code, reorganize order of some functions
- Move setting stuffs to class SettingsClass (similar to NetworkDialog)
- Fix bugs of app flow