Fixed some reference updating bugs introduced in the last commit.