First attempts to refactor scanner