refactoring and removed JOptionDialog