Refactored scanner a bit