seperated some of the code in the dialog
merge