Lots of edits to get references working.