Fixed small reference bugs/optimizations.