refactoring use set instead of hash
remove unnecessary code
don't use open class