major refactor of scanner