Refactoring ref code.