Refactored: replaced conditional with for...else statement and made slight changes to variable name