Added most of the code for the lexicographical checker