Improve ref generation.