bug in ref code