Fix a bunch of reference errors