Corrected indexing problem
Added code and tests to check for duplicate variables
Some code tidying in parse.py