Fixed major referencing bugs

Fixed ref bugs