Refactor lexer into class
Tidy state rules
Tweak of whitespace handling in tokenizer
Unit tests for lexer, with bugfixes