Refactor scan.l