Added delete dialog handling and minor refactoring