Refactor scan.c, add date tests