Add code to deal with unparseable references

Fix error: "local variable 'type' referenced before assignment"
in parse_reference