refactored scanner