scanner: refactor a bit.