Refactor reference resolution & improve coverage