rewriting scanner implementation