Create upwards pointer in first referenced element and remove self refs

Fix for bug #269