Fixed referenfe saving after id generation