Refactoring method scan()