Some refactoring on scanner