Refactor the Scanner