shorten using Set#add? and IO::foreach

A wee bit of refactoring to shorten your code! :neckbeard: