Scanner refactored: removed if from while loop