Fix bug in output ref renaming

http://manage.dimagi.com/default.asp?147618