cleaned up Scanner class. correctness of context updating needs further testing