fix out of order reference bug