Make Scanner into a class.

It should always be passed by reference.
Some more refactoring.