cleaned up code for dialogs