Dialog functionaliy and refactoring